package com.zrk.core;

import java.util.Arrays;

public class StringLearn {
    static int count;
    public static void main(String[] args) {
        // 1.转大写方法，转小写为toLowerCase
        upperCaseTest();
        printTest();

        // 2.忽略大小写比较字符串是否相等
        equalsIgnoreCaseTest();
        printTest();

        // 3.去除首位空白,只能去除英文空格，strip可以去除包括中文空格在内的空格
        trimTest();
        printTest();

        // 4.切割字符串
        splitTest();
        printTest();

        // 5.格式化字符串
        formatTest();
        printTest();
    }

    private static void formatTest() {
        String s = "Hi %s, your score is %d!";
        System.out.println(s.formatted("Alice", 80));
        System.out.println(String.format("Hi %s, your score is %.2f!", "Bob", 59.5));
    }

    private static void splitTest() {
        String s = "A,B,C,D";
        String[] split = s.split(",");
        System.out.println(Arrays.toString(split));
    }

    private static void equalsIgnoreCaseTest() {
        String s1 = "Hello";
        String s2 = "HELLO";
        System.out.println("s1 equals s2? " + s1.equalsIgnoreCase(s2));
    }

    private static void trimTest() {
        String s = "Hello ";
        System.out.println(s + "*");
        System.out.println(s.trim() + "*");
    }

    private static void printTest() {
        StringLearn.count++;
        System.out.println("****************************" + StringLearn.count);
    }

    private static void upperCaseTest() {
        String s = "Hello";
        System.out.println("s: " + s);

        s = s.toUpperCase();
        System.out.println("s: " + s);
    }
}
